<?php

/**
* 
* @author lyy
* @date 2017年10月18日下午4:13:55
*/

namespace api\controllers;

use yii\rest\ActiveController;

class ArticleController extends ActiveController
{
    public $modelClass = 'api\models\Articles';
    
    public function actions() {
        $actions = parent::actions();
        // 禁用""index,delete" 和 "create" 操作
        unset($actions['index'],$actions['view'],$actions['delete'], $actions['create']);
    
        return $actions;
    
    }
    
    /**
    * 
    * @author:liyy-k
    * @return: array
    */
    public function actionIndex()
    {
        return ['code'=>'200','msg'=>'success'];
        
//         $lists = (new \yii\db\Query())
//         ->select(['id', 'title'])
//         ->from('{{me_articles}}')
//         ->limit(10)
//         ->all();

        $modelClass = $this->modelClass;
        $lists = $modelClass::find()->all();
        
        return ['code'=>'200','msg'=>'success','data'=>$lists];
    }
    
    public function actionView()
    {
        return ['code'=>'200','msg'=>'success','data'=>['id'=>1,'title'=>'知识改变命运','description'=>'这是真的吗？']];
    }
    
    public function actionTotal()
    {
        return ['code'=>'200','msg'=>'success','data'=>2000];
    }
    
    
}